package com.fram.service.api.v1.impl;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fram.bean.api.projectplanttechnology.request.ProjectplanttechnologySearchRequest;
import com.fram.bean.api.projectplanttechnology.response.ProjectplanttechnologyDetail;
import com.fram.bean.api.projectplanttechnology.response.ProjectplanttechnologySearchResponse;
import com.fram.bean.sys.PageBean;
import com.fram.common.canstant.ErrCode;
import com.fram.common.exception.ProAffairException;
import com.fram.common.exception.ProRunTimeException;
import com.fram.mapper.ProjectPlantTechnologyMapper;
import com.fram.service.api.v1.ProjectPlantTechnologyService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

/**
 * @作者： 陳曉鬆 @时间： 2020年10月12日 - 上午10:40:56 @description：->
 */
@Service("projectPlantTechnologyService")
public class ProjectPlantTechnologyServiceImpl implements ProjectPlantTechnologyService {

	@Autowired
	private ProjectPlantTechnologyMapper projectPlantTechnologyMapper;

	@Override
	public PageInfo<ProjectplanttechnologySearchResponse> search(PageBean<ProjectplanttechnologySearchRequest> request) throws ProAffairException {
		PageHelper.startPage(request.getPageNum(), request.getPageSize());
		List<ProjectplanttechnologySearchResponse> list = projectPlantTechnologyMapper.search(request.getParam());
		if (list == null || list.size() == 0) {
			throw new ProRunTimeException(ErrCode.NO_DATA.getReturnCode(), ErrCode.NO_DATA.getReturnMsg());
		}
		return new PageInfo<>(list);
	}

	@Override
	@Transactional
	public ProjectplanttechnologyDetail detail(Long userId, Long id) throws ProAffairException {
		ProjectplanttechnologyDetail detail = projectPlantTechnologyMapper.detail(id);
		if (detail == null) {
			throw new ProRunTimeException(ErrCode.NO_DATA.getReturnCode(), ErrCode.NO_DATA.getReturnMsg());
		}
		return detail;
	}
}
